home *** CD-ROM | disk | FTP | other *** search
-
- /*****************************************************************************
- *
- * CyberSound: 14 Bit sound driver calibration program
- *
- * (c) 1995 by Christian Buchner
- *
- *****************************************************************************
- *
- * Calibrate.c
- */
-
-
- #include <intuition/intuition.h>
- #include <libraries/gadtools.h>
- #include <libraries/asl.h>
- #include <graphics/text.h>
- #include <graphics/gfxbase.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <proto/gadtools.h>
- #include <proto/icon.h>
- #include <proto/asl.h>
- #include <devices/audio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <hardware/custom.h>
- #include <hardware/intbits.h>
- #include <hardware/dmabits.h>
- #include <hardware/adkbits.h>
- #include <hardware/cia.h>
- #include <exec/execbase.h>
- #include <workbench/workbench.h>
-
-
- /* Prototypes */
-
- void OpenConfig(void);
- void SaveAs(void);
- void Quit(void);
- void ResetToDefaults(void);
- void LastSaved(void);
- void Restore(void);
- void IconToggle(void);
-
- BOOL OpenLibs(void);
- void CloseLibs(void);
-
- BOOL InitScreenWindow(void);
- void DeinitScreenWindow(void);
- void Resize(void);
- void FreeButtons(void);
- void DrawBar(struct Window *Window, UBYTE bar, BYTE value, BYTE oldvalue, UWORD pen);
-
- BOOL AllocAudio(void);
- void FreeAudio(void);
- void StartCalibSound(ULONG Frequency);
- void StopCalibSound(void);
-
- BOOL LoadData(UBYTE *Dirname, UBYTE *Filename);
- BOOL SaveData(UBYTE *EnvDir, UBYTE *Dirname, UBYTE *Filename, BOOL CreateIcon);
- void DefaultData(void);
- void ShowData(void);
-
- LONG __stdargs Message(UBYTE *Msg,UBYTE *Options,...);
-
-
-
- /* Globals */
-
- UBYTE Version[]="$VER: 14Bit Calibration 1.1 "__AMIGADATE__" by Christian Buchner";
-
- UWORD __chip HighSample;
- UWORD __chip LowSample;
-
- BYTE AdditiveArray[256]; /* Set last value to 0x7F */
-
- BYTE *Array=AdditiveArray;
-
- struct Process *MyProc;
- struct WBStartup *WBenchMsg;
-
- struct DosLibrary *DOSBase;
- struct GfxBase *GfxBase;
- struct IntuitionBase *IntuitionBase;
- struct Library *GadToolsBase;
- struct Library *AslBase;
- struct Library *IconBase;
-
- struct Screen *Screen;
- APTR VisualInfo;
- struct TextAttr *Font, Attr;
- UWORD FontX, FontY;
- UWORD GadHeight;
- UWORD GadSpace;
- struct Window *Window;
- struct Window *OldWindowPtr;
- struct Menu *Menu;
- struct Gadget *HighGad,*LowGad;
- struct Gadget *Context;
- BOOL Active=TRUE;
- UWORD pos=128;
- UWORD AreaLeft;
- UWORD AreaTop;
- UWORD AreaWidth;
- UWORD AreaHeight;
- UBYTE buffer1[20];
- UBYTE buffer2[20];
- UBYTE Drawer[160];
- UBYTE File[40];
-
- BOOL CreateIcons=FALSE;
-
- struct MsgPort *AudioReply;
- struct IOAudio *AudioRequest;
- ULONG Freq=1000;
-
-
- struct NewMenu CalibNewMenu[]=
- {
- /* nm_Type nm_Label nm_CommKey nm_Flags nm_MutualExclude nm_UserData */
- NM_TITLE, "Project", NULL, 0, 0, NULL,
- NM_ITEM, "Open...", "0", 0, 0, &OpenConfig,
- NM_ITEM, "Save As...", "A", 0, 0, &SaveAs,
- NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL,
- NM_ITEM, "Quit", "Q", 0, 0, &Quit,
- NM_TITLE, "Edit", NULL, 0, 0, NULL,
- NM_ITEM, "Reset To Defaults","D", 0, 0, &ResetToDefaults,
- NM_ITEM, "Last Saved", "L", 0, 0, &LastSaved,
- NM_ITEM, "Restore", "R", 0, 0, &Restore,
- NM_TITLE, "Settings", NULL, 0, 0, NULL,
- NM_ITEM, "Create Icons?", "I", CHECKIT|MENUTOGGLE, 0, &IconToggle,
- NM_END, NULL, NULL, 0, 0, NULL
- };
-
- #define NEWICONINDEX 10 /* Index of "Create Icons?" NewMenu item */
- #define ICONITEM 0xF802 /* Number of "Create Icons?" Item */
-
-
- UWORD ImageData[4*0x17*2]=
- {
- 0x0000,0x0000,0x0004,0x0000,
- 0x0000,0x0000,0x0001,0x0000,
- 0x0000,0x07FF,0x8000,0x4000,
- 0x0000,0x1800,0x6000,0x1000,
- 0x0000,0x20FC,0x1000,0x0800,
- 0x0000,0x4102,0x0800,0x0C00,
- 0x0000,0x4082,0x0800,0x0C00,
- 0x0000,0x4082,0x0800,0x0C00,
- 0x0000,0x2104,0x0800,0x0C00,
- 0x0000,0x1E18,0x1000,0x0C00,
- 0x0000,0x0060,0x2000,0x0C00,
- 0x0000,0x0080,0xC000,0x0C00,
- 0x0000,0x0103,0x0000,0x0C00,
- 0x0000,0x021C,0x0000,0x0C00,
- 0x0000,0x0108,0x0000,0x0C00,
- 0x0000,0x00F0,0x0000,0x0C00,
- 0x0000,0x0108,0x0000,0x0C00,
- 0x0000,0x0108,0x0000,0x0C00,
- 0x4000,0x00F0,0x0000,0x0C00,
- 0x1000,0x0000,0x0000,0x0C00,
- 0x0400,0x0000,0x0000,0x0C00,
- 0x01FF,0xFFFF,0xFFFF,0xFC00,
- 0x0000,0x0000,0x0000,0x0000,
-
- 0xFFFF,0xFFFF,0xFFF8,0x0000,
- 0xD555,0x5555,0x5556,0x0000,
- 0xD555,0x5000,0x5555,0x8000,
- 0xD555,0x47FF,0x9555,0x6000,
- 0xD555,0x5F03,0xE555,0x5000,
- 0xD555,0x3E55,0xF555,0x5000,
- 0xD555,0x3F55,0xF555,0x5000,
- 0xD555,0x3F55,0xF555,0x5000,
- 0xD555,0x5E53,0xF555,0x5000,
- 0xD555,0x4147,0xE555,0x5000,
- 0xD555,0x551F,0xD555,0x5000,
- 0xD555,0x557F,0x1555,0x5000,
- 0xD555,0x54FC,0x5555,0x5000,
- 0xD555,0x55E1,0x5555,0x5000,
- 0xD555,0x54F5,0x5555,0x5000,
- 0xD555,0x5505,0x5555,0x5000,
- 0xD555,0x54F5,0x5555,0x5000,
- 0xD555,0x54F5,0x5555,0x5000,
- 0x3555,0x5505,0x5555,0x5000,
- 0x0D55,0x5555,0x5555,0x5000,
- 0x0355,0x5555,0x5555,0x5000,
- 0x0000,0x0000,0x0000,0x0000,
- 0x0000,0x0000,0x0000,0x0000,
- };
-
- struct Image GadgetRender=
- {
- 0,0, /* LeftEdge, TopEdge */
- 0x36, 0x17, /* Width, Height */
- 2, /* Depth */
- ImageData /* ImageData */
- };
-
- UBYTE *ToolTypes[]={"ACTION=USE",NULL};
-
- struct DiskObject DefaultIcon=
- {
- WB_DISKMAGIC, /* do_Magic */
- WB_DISKVERSION, /* do_Version */
- NULL, /* do_Gadget.NextGadget */
- 0,0, /* do_Gadget.LeftEdge, TopEdge */
- 0x36, 0x17, /* do_Gadget.Width, Height */
- GFLG_GADGIMAGE|GFLG_GADGHBOX, /* do_Gadget.Flags */
- GACT_RELVERIFY|GACT_IMMEDIATE, /* do_Gadget.Activation */
- GTYP_BOOLGADGET, /* do_Gadget.GadgetType */
- &GadgetRender, /* do_Gadget.GadgetRender */
- NULL, /* do_Gadget.SelectRender */
- NULL, /* do_Gadget.GadgetText */
- 0, /* do_Gadget.MutualExclude */
- NULL, /* do_Gadget.SpecialInfo */
- 0, /* do_Gadget.GadgetID */
- (APTR)WB_DISKREVISION, /* do_Gadget.UserData */
- WBPROJECT, /* do_Type */
- (UBYTE*)"14Bit_Calibration", /* do_DefaultTool */
- ToolTypes, /* do_ToolTypes */
- NO_ICON_POSITION, /* do_CurrentX */
- NO_ICON_POSITION, /* do_CurrentY */
- NULL, /* do_DrawerData */
- NULL, /* do_ToolWindow */
- 4096 /* do_StackSize */
- };
-
-
- UBYTE *Template="FROM,EDIT/S,USE/S,SAVE/S,PUBSCREEN/K";
-
- struct ArgArray
- {
- UBYTE *aa_From;
- ULONG aa_Edit;
- ULONG aa_Use;
- ULONG aa_Save;
- UBYTE *aa_PubScreen;
- };
-
- UBYTE PubScreenName[60]="Workbench";
-
- struct ArgArray AA =
- {
- NULL,
- FALSE,
- FALSE,
- FALSE,
- NULL,
- };
-
-
- long __saveds main(void)
- {
- BOOL Audio;
- struct IntuiMessage *MyMsg,MsgCopy;
-
- MyProc=(struct Process*)FindTask(NULL);
- if (MyProc->pr_CLI==NULL)
- {
- WaitPort(&MyProc->pr_MsgPort);
- WBenchMsg=(struct WBStartup*)GetMsg(&MyProc->pr_MsgPort);
- }
-
- if (OpenLibs())
- {
- if (!WBenchMsg)
- {
- struct RDArgs *RDArgs;
-
- if (!(RDArgs=ReadArgs(Template, (LONG*)&AA, NULL)))
- {
- PrintFault(IoErr(),NULL);
- Active=FALSE;
- }
- else
- {
- if (AA.aa_From)
- {
- strcpy(File,FilePart(AA.aa_From));
- strncpy(Drawer,AA.aa_From,(ULONG)FilePart(AA.aa_From)-(ULONG)AA.aa_From);
- }
- if (AA.aa_PubScreen)
- {
- strcpy(PubScreenName,AA.aa_PubScreen);
- }
- FreeArgs(RDArgs);
- }
- }
- else
- {
- UWORD Arg=0;
- struct DiskObject *DiskObject;
- BPTR OldLock;
- UBYTE *String;
-
- if (WBenchMsg->sm_NumArgs>1)
- {
- Arg=1;
- NameFromLock(WBenchMsg->sm_ArgList[Arg].wa_Lock,Drawer,sizeof(Drawer));
- strcpy(File,WBenchMsg->sm_ArgList[Arg].wa_Name);
- }
-
- OldLock=CurrentDir(WBenchMsg->sm_ArgList[Arg].wa_Lock);
- if (DiskObject=GetDiskObject(WBenchMsg->sm_ArgList[Arg].wa_Name))
- {
- if (String=FindToolType(DiskObject->do_ToolTypes,"ACTION"))
- {
- if (MatchToolValue(String,"EDIT"))
- {
- AA.aa_Edit=TRUE;
- }
- if (MatchToolValue(String,"USE"))
- {
- AA.aa_Use=TRUE;
- }
- if (MatchToolValue(String,"SAVE"))
- {
- AA.aa_Save=TRUE;
- }
- }
- if (String=FindToolType(DiskObject->do_ToolTypes,"CREATEICONS"))
- {
- if (MatchToolValue(String,"YES"))
- {
- CalibNewMenu[NEWICONINDEX].nm_Flags |= CHECKED;
- CreateIcons=TRUE;
- }
- if (MatchToolValue(String,"NO"))
- {
- CalibNewMenu[NEWICONINDEX].nm_Flags &= ~(CHECKED);
- CreateIcons=FALSE;
- }
- }
- if (String=FindToolType(DiskObject->do_ToolTypes,"PUBSCREEN"))
- {
- strcpy(PubScreenName,String);
- }
- FreeDiskObject(DiskObject);
- }
- CurrentDir(OldLock);
- }
-
- if (Active)
- {
- BOOL Success=FALSE;
-
- if (strlen(File))
- {
- if (!(Success=LoadData(Drawer,File)))
- {
- Message("Error loading calibration from file '%s'\nin directory '%s'","Okay",File,Drawer);
- }
- }
-
- if (!Success)
- {
- Success=LoadData("ENV:CyberSound/SoundDrivers","14Bit_Calibration");
- }
-
- if (!Success)
- {
- DefaultData();
- }
-
- if (!(AA.aa_Use || AA.aa_Save)) AA.aa_Edit=TRUE;
-
- if (AA.aa_Edit)
- {
- while (!(Audio=AllocAudio()))
- {
- if (!Message("ERROR: Cannot allocate the audio channels!\n"
- "Quit all programs using the audio hardware and try again.","Retry|Cancel"))
- {
- break;
- }
- }
-
- if (Audio)
- {
- if (InitScreenWindow())
- {
- Resize();
-
- StartCalibSound(Freq);
-
- Message("CyberSound 14 bit driver calibration program\n"
- "Copyright ©1995 by Christian Buchner\n"
- "\n"
- "Please note:\n"
- "------------\n"
- "I am NOT responsible for any damage that may happen to your\n"
- "HIFI equipment. Use this software at your own risk!\n"
- "\n"
- "Follow these instructions and noting harmful will happen\n"
- "to your HIFI set.\n"
- "\n"
- "The audio channels have been allocated at maximum priority.\n"
- "No system compliant program can interfere.","I see");
-
- Message("Instructions for calibrating the 14 bit driver\n"
- "----------------------------------------------\n"
- "Turn up the volume of your amplifier until you can hear a beep.\n"
- "Use the cursor left-right keys to move the cursor (white line) in\n"
- "the spectrum. Use the cursor up-down keys for calibration.\n"
- "\n"
- "Your aim is to make the beep disappear as much as possible in all\n"
- "positions of the spectrum.\n"
- "\n"
- "The + / - keys change the frequency of the calibration tone.\n"
- "\n"
- "Save your settings when finished.\n"
- "\n"
- "THEN TURN DOWN THE VOLUME OF YOUR AMPLIFIER!\n"
- "You will be warned again before the program exits.","I see");
-
- while(Active)
- {
- HighSample=(((pos-128)&0xFF)<<8)+((pos-127)&0xFF);
- LowSample =((((UWORD)Array[pos])&0xFF)<<8);
-
- sprintf(buffer1,"%04lx",(ULONG)HighSample);
- GT_SetGadgetAttrs(HighGad, Window, NULL, GTTX_Text, buffer1, TAG_DONE);
- sprintf(buffer2,"%05lx",(ULONG)LowSample );
- GT_SetGadgetAttrs(LowGad, Window, NULL, GTTX_Text, buffer2, TAG_DONE);
-
- while (!(MyMsg=GT_GetIMsg(Window->UserPort)))
- {
- Wait(1L<<Window->UserPort->mp_SigBit);
- }
- CopyMem((APTR)MyMsg,(APTR)&MsgCopy,sizeof(struct IntuiMessage));
- GT_ReplyIMsg(MyMsg);
-
- if (MsgCopy.Class==IDCMP_RAWKEY)
- {
- /* Cursor right */
- if (MsgCopy.Code==0x4e)
- {
- if (pos<254)
- {
- DrawBar(Window,pos,Array[pos],Array[pos],3);
- pos++;
- DrawBar(Window,pos,Array[pos],Array[pos],2);
- }
- }
- /* Cursor left */
- if (MsgCopy.Code==0x4f)
- {
- if (pos>0)
- {
- DrawBar(Window,pos,Array[pos],Array[pos],3);
- pos--;
- DrawBar(Window,pos,Array[pos],Array[pos],2);
- }
- }
- /* Cursor up */
- if (MsgCopy.Code==0x4c)
- {
- if (Array[pos]<127)
- {
- DrawBar(Window,pos,Array[pos]+1,Array[pos],2);
- Array[pos]++;
- }
- }
- /* Cursor down */
- if (MsgCopy.Code==0x4d)
- {
- if (Array[pos]>-128)
- {
- DrawBar(Window,pos,Array[pos]-1,Array[pos],2);
- Array[pos]--;
- }
- }
- }
- if (MsgCopy.Class==IDCMP_VANILLAKEY)
- {
- /* + : Increment frequency */
- if (MsgCopy.Code=='+')
- {
- if (Freq<20000)
- {
- Freq+=100;
- StartCalibSound(Freq);
- }
- }
- /* - : Decrement frequency */
- if (MsgCopy.Code=='-')
- {
- if (Freq>100)
- {
- Freq-=100;
- StartCalibSound(Freq);
- }
- }
- }
- if (MsgCopy.Class==IDCMP_NEWSIZE)
- {
- Resize();
- }
- if (MsgCopy.Class==IDCMP_GADGETUP)
- {
- struct Gadget *IA=(struct Gadget*)MyMsg->IAddress;
- if (IA->GadgetID==1)
- {
- AA.aa_Save=TRUE;
- AA.aa_Use=FALSE;
- Active=FALSE;
- }
- if (IA->GadgetID==2)
- {
- AA.aa_Save=FALSE;
- AA.aa_Use=TRUE;
- Active=FALSE;
- }
- if (IA->GadgetID==3)
- {
- AA.aa_Save=FALSE;
- AA.aa_Use=FALSE;
- Active=FALSE;
- }
- }
- if (MsgCopy.Class==IDCMP_MENUPICK)
- {
- struct MenuItem *n;
- void (*func)(void);
-
- while( MsgCopy.Code != MENUNULL )
- {
- n = ItemAddress( Menu, MsgCopy.Code );
- func = (void *)(GTMENUITEM_USERDATA( n ));
- if (func) func();
- MsgCopy.Code = n->NextSelect;
- }
- }
- }
-
- Message("*** WARNING! ***\n"
- "TURN DOWN THE VOLUME OF YOUR AMPLIFIER BACK TO NORMAL VOLUME!\n"
- ">>> NOW! <<<\n"
- "This will prevent serious damage of your HIFI equipment.",
- "Yes, the volume is down");
-
- StopCalibSound();
-
- DeinitScreenWindow();
- }
- FreeAudio();
- }
- }
- }
-
- if (AA.aa_Use || AA.aa_Save)
- {
- SaveData("ENV:",NULL,"14Bit_Calibration",CreateIcons);
-
- if (AA.aa_Save)
- {
- SaveData("ENVARC:",NULL,"14Bit_Calibration",CreateIcons);
- }
- }
-
- CloseLibs();
- }
-
- if (WBenchMsg)
- {
- Forbid();
- ReplyMsg(WBenchMsg);
- }
- }
-
-
- void OpenConfig(void)
- {
- APTR requester;
- BOOL Success=FALSE;
-
- if (requester=AllocAslRequestTags(ASL_FileRequest, TAG_DONE))
- {
- if (AslRequestTags(requester, ASLFR_Window, Window,
- ASLFR_InitialDrawer, Drawer,
- ASLFR_InitialFile, File,
- ASLFR_TitleText, "Load calibration...",
- TAG_DONE))
- {
- strcpy(Drawer,((struct FileRequester*)requester)->fr_Drawer);
- strcpy(File,((struct FileRequester*)requester)->fr_File);
-
- if (!(Success=LoadData(Drawer,File)))
- {
- Message("Error loading calibration from file '%s'\nin directory '%s'","Okay",File,Drawer);
- }
-
- if (!Success)
- {
- Success=LoadData("ENV:CyberSound/SoundDrivers","14Bit_Calibration");
- }
-
- if (!Success)
- {
- DefaultData();
- }
-
- ShowData();
-
- }
- FreeAslRequest(requester);
- }
- }
-
-
- void SaveAs(void)
- {
- APTR requester;
-
- if (requester=AllocAslRequestTags(ASL_FileRequest, TAG_DONE))
- {
- if (AslRequestTags(requester, ASLFR_Window, Window,
- ASLFR_InitialDrawer, Drawer,
- ASLFR_InitialFile, File,
- ASLFR_TitleText, "Save calibration as...",
- ASLFR_DoSaveMode, TRUE,
- TAG_DONE))
- {
- strcpy(Drawer,((struct FileRequester*)requester)->fr_Drawer);
- strcpy(File,((struct FileRequester*)requester)->fr_File);
-
- if (!SaveData(NULL,Drawer,File,CreateIcons))
- {
- Message("Error saving calibration to file '%s'\nin directory '%s'","Okay",File,Drawer);
- }
- }
- FreeAslRequest(requester);
- }
- }
-
-
- void Quit(void)
- {
- Active=FALSE;
- }
-
-
- void ResetToDefaults(void)
- {
- DefaultData();
- ShowData();
- }
-
-
- void LastSaved(void)
- {
- if (!LoadData("ENVARC:CyberSound/SoundDrivers","14Bit_Calibration"))
- {
- DisplayBeep(NULL);
- DefaultData();
- }
- ShowData();
- }
-
-
- void Restore(void)
- {
- if (!LoadData("ENV:CyberSound/SoundDrivers","14Bit_Calibration"))
- {
- DisplayBeep(NULL);
- DefaultData();
- }
- ShowData();
- }
-
-
- void IconToggle(void)
- {
- CreateIcons=ItemAddress(Menu,ICONITEM)->Flags&CHECKED ? TRUE : FALSE;
- }
-
-
- BOOL OpenLibs(void)
- {
- BOOL Success=FALSE;
-
- if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))
- {
- if (IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",37))
- {
- if (GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",37))
- {
- if (GadToolsBase=(struct Library*)OpenLibrary("gadtools.library",37))
- {
- if (IconBase=OpenLibrary("icon.library",37))
- {
- if (!(AslBase=OpenLibrary("asl.library",37)))
- {
- Message("Cannot open asl library!","Okay");
- }
- else
- {
- Success=TRUE;
- }
- }
- }
- }
- }
- }
- if (!Success)
- {
- CloseLibs();
- }
- return(Success);
- }
-
-
- void CloseLibs(void)
- {
- if (AslBase)
- {
- CloseLibrary(AslBase);
- AslBase=NULL;
- }
- if (IconBase)
- {
- CloseLibrary(IconBase);
- IconBase=NULL;
- }
- if (GadToolsBase)
- {
- CloseLibrary(GadToolsBase);
- GadToolsBase=NULL;
- }
- if (GfxBase)
- {
- CloseLibrary((struct Library*)GfxBase);
- GfxBase=NULL;
- }
- if (IntuitionBase)
- {
- CloseLibrary((struct Library*)IntuitionBase);
- IntuitionBase=NULL;
- }
- if (DOSBase)
- {
- CloseLibrary((struct Library*)DOSBase);
- DOSBase=NULL;
- }
- }
-
-
- BOOL InitScreenWindow(void)
- {
- BOOL Success=FALSE;
-
- if (!(Screen=LockPubScreen(PubScreenName)))
- {
- Message("Unable to lock public screen '%s'","Okay",PubScreenName);
- }
- else
- {
- ScreenToFront(Screen);
-
- if (VisualInfo=GetVisualInfo(Screen,TAG_DONE))
- {
- Forbid();
- Font = &Attr;
- Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
- Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
- FontX = GfxBase->DefaultFont->tf_XSize;
- Permit();
-
- GadHeight=FontY+7;
- GadSpace=2*GadHeight+12;
-
- if (!(Window=OpenWindowTags(NULL, WA_Title,"14 bit driver calibration",
- WA_PubScreen, Screen,
- WA_InnerWidth, 255+20,
- WA_InnerHeight,128+GadSpace+12,
- WA_IDCMP, IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_NEWSIZE|IDCMP_MENUPICK|BUTTONIDCMP,
- WA_SizeGadget, TRUE,
- WA_DragBar,TRUE,
- WA_DepthGadget, TRUE,
- WA_Activate, TRUE,
- WA_MaxWidth,-1,
- WA_MaxHeight,-1,
- WA_NewLookMenus,TRUE,
- TAG_END)))
- {
- Message("Unable to open window.","Okay");
- }
- else
- {
- OldWindowPtr=MyProc->pr_WindowPtr;
- MyProc->pr_WindowPtr=Window;
-
- if (Menu=(struct Menu *)CreateMenus(CalibNewMenu, TAG_DONE))
- {
- LayoutMenus(Menu, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_DONE);
- SetMenuStrip(Window, Menu);
-
- Success=TRUE;
- }
- }
- }
- }
- return(Success);
- }
-
-
- void DeinitScreenWindow(void)
- {
- FreeButtons();
-
- if (Window)
- {
- MyProc->pr_WindowPtr=OldWindowPtr;
- ClearMenuStrip(Window);
- if (Menu)
- {
- FreeMenus(Menu);
- Menu=NULL;
- }
- CloseWindow(Window);
- Window=NULL;
- }
- if (VisualInfo)
- {
- FreeVisualInfo(VisualInfo);
- VisualInfo=NULL;
- }
- if (Screen)
- {
- UnlockPubScreen(NULL,Screen);
- Screen=NULL;
- }
- }
-
-
- void Resize(void)
- {
- struct NewGadget NG;
- struct Gadget *g;
- UWORD GadWidth;
-
- FreeButtons();
-
- EraseRect(Window->RPort,Window->BorderLeft,Window->BorderTop,Window->Width-Window->BorderRight-1,Window->Height-Window->BorderBottom-1);
- RefreshWindowFrame(Window);
-
- AreaLeft=Window->BorderLeft+10;
- AreaTop=Window->BorderTop+6;
- AreaWidth=Window->Width-Window->BorderLeft-Window->BorderRight-20;
- AreaHeight=Window->Height-Window->BorderTop-Window->BorderBottom-12-GadSpace;
-
- GadWidth=AreaWidth/4;
-
- DrawBevelBox(Window->RPort,AreaLeft-2,AreaTop-2,AreaWidth+4,AreaHeight+4,GTBB_Recessed,TRUE,GT_VisualInfo,VisualInfo,TAG_DONE);
-
- if (g=CreateContext(&Context))
- {
- NG.ng_LeftEdge=AreaLeft-2+4*FontX+10;
- NG.ng_TopEdge=AreaTop+AreaHeight+7;
- NG.ng_Width=GadWidth;
- NG.ng_Height=GadHeight;
- NG.ng_GadgetText="High";
- NG.ng_TextAttr=Font;
- NG.ng_GadgetID=0;
- NG.ng_Flags=PLACETEXT_LEFT;
- NG.ng_VisualInfo=VisualInfo;
- NG.ng_UserData=NULL;
-
- if (g=HighGad=CreateGadget(TEXT_KIND, g, &NG, GTTX_Border, TRUE, GTTX_Justification, GTJ_CENTER, TAG_DONE))
- {
- NG.ng_LeftEdge=AreaLeft+AreaWidth-NG.ng_Width+2;
- NG.ng_GadgetText="Low";
-
- if (g=LowGad=CreateGadget(TEXT_KIND, g, &NG, GTTX_Border, TRUE, GTTX_Justification, GTJ_CENTER, TAG_DONE))
- {
- NG.ng_LeftEdge=AreaLeft-2;
- NG.ng_TopEdge=AreaTop+AreaHeight+(GadSpace-GadHeight)+1;
- NG.ng_Width=GadWidth;
- NG.ng_Height=GadHeight;
- NG.ng_GadgetText="Save";
- NG.ng_GadgetID=1;
- NG.ng_Flags=PLACETEXT_IN;
-
- if (g=CreateGadget(BUTTON_KIND, g, &NG, TAG_DONE))
- {
- NG.ng_LeftEdge=AreaLeft+AreaWidth/2-GadWidth/2;
- NG.ng_GadgetText="Use";
- NG.ng_GadgetID=2;
-
- if (g=CreateGadget(BUTTON_KIND, g, &NG, TAG_DONE))
- {
- NG.ng_LeftEdge=AreaLeft+AreaWidth-GadWidth+2;
- NG.ng_GadgetText="Cancel";
- NG.ng_GadgetID=3;
-
- if (g=CreateGadget(BUTTON_KIND, g, &NG, TAG_DONE))
- {
- }
- }
- }
- }
- }
-
- AddGList(Window, Context, -1, -1, NULL);
- RefreshGList(Context, Window, NULL, -1);
- GT_RefreshWindow(Window, NULL);
- }
- ShowData();
- }
-
-
- void FreeButtons(void)
- {
- if (Context)
- {
- RemoveGList(Window,Context,-1);
- FreeGadgets(Context);
- Context=NULL;
- }
- }
-
-
- void DrawBar(struct Window *Window, UBYTE bar, BYTE value, BYTE oldvalue, UWORD pen)
- {
- UWORD temp, ymin, ymax;
-
- UWORD Mid=AreaTop+(AreaHeight-1)/2;
- UWORD Left=AreaLeft+(ULONG)bar*AreaWidth/255;
- UWORD Right=AreaLeft+(ULONG)(bar+1)*AreaWidth/255-1;
-
- SetAPen(Window->RPort,pen);
-
- if (abs(value)<abs(oldvalue))
- {
- ymin=Mid-(LONG)oldvalue*AreaHeight/256;
- ymax=Mid-(LONG)value*AreaHeight/256;
-
- if (ymin>ymax) {temp=ymax;ymax=ymin;ymin=temp;}
- EraseRect(Window->RPort,Left,ymin,Right,ymax);
- }
-
- ymin=Mid;
- ymax=Mid-(LONG)value*AreaHeight/256;
-
- if (ymin>ymax) {temp=ymax;ymax=ymin;ymin=temp;}
- RectFill(Window->RPort,Left,ymin,Right,ymax);
- }
-
-
- BOOL AllocAudio(void)
- {
- BOOL Success=FALSE;
-
- UBYTE ChannelMap[]={0xf};
-
- if (AudioReply=CreateMsgPort())
- {
- if (AudioRequest=CreateIORequest(AudioReply,sizeof(struct IOAudio)))
- {
- AudioRequest->ioa_Request.io_Message.mn_Node.ln_Pri=127;
- AudioRequest->ioa_Data=ChannelMap;
- AudioRequest->ioa_Length=sizeof(ChannelMap);
- AudioRequest->ioa_Request.io_Flags=ADIOF_NOWAIT;
-
- if (!OpenDevice("audio.device",0,(struct IORequest*)AudioRequest,0))
- {
- Success=TRUE;
- }
- }
- }
- if (!Success) FreeAudio();
- return(Success);
- }
-
-
- void FreeAudio(void)
- {
- if (AudioRequest)
- {
- if (AudioRequest->ioa_Request.io_Device)
- {
- CloseDevice((struct IORequest*)AudioRequest);
- AudioRequest->ioa_Request.io_Device=NULL;
- }
- DeleteIORequest(AudioRequest);
- AudioRequest=NULL;
- }
- if (AudioReply)
- {
- DeleteMsgPort(AudioReply);
- AudioReply=NULL;
- }
- }
-
-
- void StartCalibSound(ULONG Frequency)
- {
- struct Custom *custom = (struct Custom*)0xdff000;
- struct CIA *ciaa=(struct CIA*)0xbfe001;
-
- ciaa->ciapra |= CIAF_LED;
- custom->dmacon=DMAF_AUDIO;
- custom->adkcon= ADKF_USE3PN|ADKF_USE2P3|
- ADKF_USE1P2|ADKF_USE0P1|
- ADKF_USE3VN|ADKF_USE2V3|
- ADKF_USE1V2|ADKF_USE0V1;
- custom->intena=INTF_AUD0|INTF_AUD1|INTF_AUD2|INTF_AUD3;
-
- Delay(1);
-
- custom->aud[0].ac_ptr=&HighSample;
- custom->aud[1].ac_ptr=&HighSample;
- custom->aud[2].ac_ptr=&LowSample;
- custom->aud[3].ac_ptr=&LowSample;
-
- custom->aud[0].ac_vol=
- custom->aud[1].ac_vol=64;
- custom->aud[2].ac_vol=
- custom->aud[3].ac_vol=1;
-
- custom->aud[0].ac_len=
- custom->aud[1].ac_len=
- custom->aud[2].ac_len=
- custom->aud[3].ac_len=1;
-
- custom->aud[0].ac_per=
- custom->aud[1].ac_per=
- custom->aud[2].ac_per=
- custom->aud[3].ac_per=(*(struct ExecBase**)(4))->ex_EClockFrequency*5/Frequency;;
-
- custom->dmacon=DMAF_SETCLR|DMAF_AUDIO;
- }
-
-
- void StopCalibSound(void)
- {
- struct Custom *custom = (struct Custom*)0xdff000;
-
- custom->dmacon=DMAF_SETCLR|DMAF_AUDIO;
- custom->aud[0].ac_vol=
- custom->aud[1].ac_vol=
- custom->aud[2].ac_vol=
- custom->aud[3].ac_vol=0;
- }
-
-
- BOOL LoadData(UBYTE *Dirname, UBYTE *Filename)
- {
- BOOL Success=FALSE;
- BPTR FH;
- BPTR DirLock,OldDir;
-
- if (DirLock=Lock(Dirname,ACCESS_READ))
- {
- OldDir=CurrentDir(DirLock);
- if (FH=Open(Filename,MODE_OLDFILE))
- {
- if (Read(FH,AdditiveArray,sizeof(AdditiveArray))==sizeof(AdditiveArray))
- {
- Success=TRUE;
- }
- Close(FH);
- }
- CurrentDir(OldDir);
- UnLock(DirLock);
- }
-
- return(Success);
- }
-
-
- BOOL SaveData(UBYTE *EnvDir, UBYTE *Dirname, UBYTE *Filename, BOOL CreateIcon)
- {
- BOOL Success=FALSE;
- BPTR OldDir=NULL;
- BPTR DirLock=NULL;
- BPTR EnvLock=NULL,CybLock=NULL,SndLock=NULL;
- BPTR FH;
-
- if (EnvDir)
- {
- if (EnvLock=Lock(EnvDir,ACCESS_READ))
- {
- OldDir=CurrentDir(EnvLock);
-
- if (!(CybLock=Lock("CyberSound",ACCESS_READ)))
- {
- CybLock=CreateDir("CyberSound");
- }
- if (CybLock)
- {
- CurrentDir(CybLock);
-
- if (!(SndLock=Lock("SoundDrivers",ACCESS_READ)))
- {
- SndLock=CreateDir("SoundDrivers");
- }
- if (SndLock)
- {
- CurrentDir(SndLock);
- Success=TRUE;
- }
- }
- }
- }
- else
- {
- if (DirLock=Lock(Dirname,ACCESS_READ))
- {
- OldDir=CurrentDir(DirLock);
- Success=TRUE;
- }
- }
-
- if (Success)
- {
- Success=FALSE;
-
- if (FH=Open(Filename,MODE_NEWFILE))
- {
- if (Write(FH,AdditiveArray,sizeof(AdditiveArray))==sizeof(AdditiveArray))
- {
- if (CreateIcon)
- {
- PutDiskObject(Filename,&DefaultIcon);
- }
- Success=TRUE;
- }
- Close(FH);
- }
- }
-
- if (OldDir) CurrentDir(OldDir);
- if (SndLock) UnLock(SndLock);
- if (CybLock) UnLock(CybLock);
- if (EnvLock) UnLock(EnvLock);
- if (DirLock) UnLock(DirLock);
-
- return(Success);
- }
-
-
- void DefaultData(void)
- {
- UWORD i;
- for (i=0;i<255;i++) Array[i]=0x55;
- Array[255]=0x7f;
- }
-
-
- void ShowData(void)
- {
- UWORD i;
-
- EraseRect(Window->RPort,AreaLeft,AreaTop,AreaLeft+AreaWidth-1,AreaTop+AreaHeight-1);
-
- for (i=0;i<255;i++)
- {
- if (i==pos)
- DrawBar(Window,i,Array[i],0,2);
- else
- DrawBar(Window,i,Array[i],0,3);
- }
- }
-
-
- /* Show a message to the user */
-
- LONG __stdargs Message(UBYTE *Msg,UBYTE *Options,...)
- {
- LONG retval;
-
- va_list Arg;
- struct EasyStruct Req={sizeof(struct EasyStruct),0,"14Bit Calibration",0, NULL};
- Req.es_TextFormat=Msg;
- Req.es_GadgetFormat=Options;
- va_start(Arg,Options);
-
- if (WBenchMsg || Window || strchr(Options,'|'))
- {
- retval=EasyRequestArgs(NULL,&Req,0,Arg);
- }
- else
- {
- VPrintf(Msg,Arg);
- Printf("\n");
- retval=0;
- }
- va_end(Arg);
-
- return(retval);
- }
-